import 'package:flutter/material.dart';
import 'package:moose_app/ui/values/colors.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/scroll/scroller_configuration_wrapper.dart';
import 'package:moose_app/ui/widgets/sticky_tabbar_delegate.dart';

import 'order_item.dart';

class ATHOrderBody extends StatefulWidget {
  @override
  _ATHOrderBodyState createState() => _ATHOrderBodyState();
}

class _ATHOrderBodyState extends State<ATHOrderBody>
    with SingleTickerProviderStateMixin {
  TabController _orderTabController;

  List<String> _orderTabsText = ["全部", "待付款", "待发货", "待收货", "待评价", "退款/售后"];

  List<Tab> _orderTabs = [];

  @override
  void initState() {
    _orderTabsText.forEach((element) {
      _orderTabs.add(Tab(
        text: element,
      ));
    });

    _orderTabController =
        TabController(initialIndex: 0, length: _orderTabs.length, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ATHScrollerConfigurationWrapper(
      child: CustomScrollView(
        slivers: <Widget>[
//          SliverAppBar(
//            title: Text(
//              "订单管理",
//              style: TextStyle(color: kColor33),
//            ),
//            pinned: true,
//            elevation: 0,
////            expandedHeight: 250,
////            flexibleSpace: FlexibleSpaceBar(
////              title: Text(S.of(context).orderTitle),
////              background: Image.network(
////                'http://img1.mukewang.com/5c18cf540001ac8206000338.jpg',
////                fit: BoxFit.cover,
////              ),
////            ),
//          ),
          SliverPersistentHeader(
            pinned: true,
            delegate: ATHStickyTabBarDelegate(
                child: _buildTabBar(),
                onMorePress: () {
                  print("More Icon Press");
                }),
          ),
          SliverFillRemaining(
            child: _buildTabBarView(),
          ),
        ],
      ),
    );
  }

  TabBarView _buildTabBarView() {
    return TabBarView(
      controller: _orderTabController,
      children: _orderTabsText
          .map((e) => ListView.builder(
              itemCount: 6,
              itemBuilder: (context, index) {
                return ATHOrderItem();
              }))
          .toList(),
    );
  }

  Widget _buildTabBar() {
    return TabBar(
      isScrollable: true,
      controller: _orderTabController,
      tabs: _orderTabs,
      indicatorColor: kColorFF6200,
      indicatorSize: TabBarIndicatorSize.label,
      labelStyle: TextStyle(fontSize: kFontSize32, fontWeight: FontWeight.bold),
      labelColor: kColorFF6200,
      unselectedLabelStyle: TextStyle(fontSize: kFontSize30),
      unselectedLabelColor: kColor99,
    );
  }
}
